<?php
class AvisosController extends AppController {

	var $name = 'Avisos';
	var $helpers = array('Html', 'Form', 'Time');

	function index() {
		$this->Aviso->recursive = 0;
		//$this->set('avisos', $this->paginate());
		$this->set('avisos', $this->Aviso->find('all', array('order'=>'fecha DESC', 'recursive'=>0)));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash('Aviso invalido', 'error'); //__('Invalid Aviso.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('aviso', $this->Aviso->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Aviso->create();
			if ($this->Aviso->save($this->data)) {
				$this->Session->setFlash(__('The Aviso has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Aviso could not be saved. Please, try again.', true));
			}
		}
		$ciclos = $this->Aviso->Ciclo->find('list');
		$usuarios = $this->Aviso->Usuario->find('list');
		$this->set(compact('ciclos', 'usuarios'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Aviso', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Aviso->save($this->data)) {
				$this->Session->setFlash(__('The Aviso has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Aviso could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Aviso->read(null, $id);
		}
		$ciclos = $this->Aviso->Ciclo->find('list');
		$usuarios = $this->Aviso->Usuario->find('list');
		$this->set(compact('ciclos','usuarios'));
	}
	
	function read($ciclo = null)
	{
		if(!$ciclo)
		{
			$this->Session->setFlash(__('ciclo invalido', true));
			$this->redirect(array('action'=>'index'));
		}
		else
			$this->set('avisos', $this->Aviso->findByCiclo($ciclo));
	}
	
	function delete($id = null)
	{
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Aviso', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Aviso->del($id)) {
			$this->Session->setFlash(__('Aviso eliminado', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>